//
//  CommonAPI.h
//  ClinicalCollections
//
//  Created by janakiraman gopinath on 2/1/13.
//  Copyright (c) 2013 GOPI. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ClinTrialWebViewController.h"
#import "ClinicalAnnotation.h"
#import "SearchViewController.h"
#import "GraphViewController.h"
#import "ClinicalAnnotation.h"
#import "GenericTableViewController.h"
#import "ClinicalCollectionsViewController.h"
#import "Groups.h"
#import "ClinicalTrialGov+ClinicalTrialGov.h"
#import "Location+Location.h"   
#import "Status+Status.h"
#import "Search+Search.h"
#import "Condition+Condition.h" 
#import "Groups+Groups.h"
#import "GroupTypes+GroupTypes.h"
#import "Measure+Measure.h"
#import "Values+Values.h"
#import "Categories+Categories.h"
#import "ArmGroups+ArmGroups.h"
#import "Outcome+Outcome.h"
#import "Intervention+intervention.h"
#import "OtherName+OtherName.h"
#import "ArmGroupLabel+ArmGroupLabel.h"
#import "Eligibility+Eligibility.h"

#import "ClinicalCollectionsViewController.h"
#import "GenericTableViewController.h"

#import "DatabaseHelper.h"
#import "SingleGraphViewController.h"
#import "RecentViewsController.h"
#import "CCViewStudyViewController.h"


#define MAX_CAPACITY 100
#define contains(x,y) [x rangeOfString:y options:NSCaseInsensitiveSearch].length >0;
#define CLINICAL_COLLECTIONS_URL "http://www.clinicalcollections.org/trials/viewer?term=%@#view=view_timelinebyphases"
#define CLINICAL_TRIALSGOV_URL "http://www.clinicaltrials.gov/ct2/show/%@"
#define STUDIES_TITLE "Studies"
#define GRAPHS "Graphs"
#define COLLECTIONS "Collections"
#define CLINICAL_COLLECTIONS "ClinicalCollections"
#define BAR_CHART_IMAGE "17-bar-chart.png"
#define GENERIC_VIEW_CONTROLLER_CLASS [GenericTableViewController class]
#define SEARCH_VIEW_CONTROLLER_CLASS [SearchViewController class]
#define BAR_FOR_SEARCH "BarForSearch"
#define SEARCH_TABLE_VIEW "SearchTableView"
#define TITLE_LABEL "TitleLabel"
#define SEGUE_MAIN "segueToMain"
#define CLINICAL_COLLECTIONS_STRING "ClinicalCollections"
#define CLINICAL_COLLECTIONS_DATABASE "ClinicalCollectionsDatabase"
#define COMMA ","
#define DESCRIPTION @"description"
#define OVERALL_STUDY @"Overall Study"
#define BASELINE @"baseline"
#define NUMBER_OF_PARTICIPANTS @"Number of Participants"
#define DATA @"data"
#define GRAPH_VIEW @"graph_view"
#define PIE_CHART @"pieChart"
#define BAR_CHART @"barChart"
#define CHART_TYPE @"chartType"
#define CLINICAL_TRIAL_GOV_HITS @"ClinicalTrialGov Hit(s)"
#define CONDITIONS_HITS @"Condition Hit(s)"
#define GROUPS_HITS @"Treatment Hit(s)"
#define LOCATION_HITS @"Location Hit(s)"
#define OUTCOME_HITS @"Outcome Hit(s)"
#define INTERVENTION_HITS @"intervention Hit(s)"
#define ARM_GROUP_HITS @"Arm Group Hit(s)"
#define OTHER_NAME_HITS @"Other Name Hit(s)"
#define ARM_GROUP_LABEL_HITS @"Arm Group Label Hit(s)"
#define ELIGIBILITY_HITS @"Eligibility Hit(s)"
#define STUDY_TYPE_HITS @"Study Type Hit(s)"
#define STUDY_DESIGN_HITS @"Study Design Hit(s)"
#define PHASE_HITS @"Study Design Hit(s)"

#define NCTID @"nctid"
#define DEFAULTS_COUNT 20
#define RECENT_EVENTS @"recent_events"

@interface CommonAPI : NSObject
{
    enum PATH_FOR_TAB_VIEW_CONTROLLER  {CLINICALTRIALGOV, CLINICALTRIALCATALOG , NA};
    
    enum VIEW_CONTROLLER { GENERICVIEWCONTROLLER,
                           SEARCHVIEWCONTROLLER,
                           CLINICALCOLLECTIONSVIEWCONTROLLER,
                           GRAPHVIEWCONTROLLER,
                           CCVIEWSTUDYVIEWCONTROLLER,
                           CLINICALTRIALWEBVIEWCONTROLLER};
   
    enum LEFT_OR_RIGHT {LEFT,RIGHT};
    
}


+ (id) targetViewControllerFrom:(id)viewController
                        forPath:(enum PATH_FOR_TAB_VIEW_CONTROLLER) path
                           side:(enum LEFT_OR_RIGHT) leftOrRight
        returningViewController:(enum VIEW_CONTROLLER) targetViewController;


+ (void) mergeArray:(NSMutableArray *) baseArray withArray:(NSArray *) arrays;

+ (NSArray *) createAnnotations:(NSArray *)array
              primaryAnnotation:(BOOL) primary
               accessoryEnabled:(BOOL) accessory
                          title:(NSString *) title;
+ (ClinicalTrialGov *) clinicalTrialGov:(NSString *) nctId
                             fromSearch:(Search *) search;
+(BOOL)doesStudyContainAnalytics:(ClinicalTrialGov*)clinicalTrialGov;

+(void)download:(void (^)())block;
+(void)main:(void (^)())block;

+ (id) getObjectFromSet:(NSArray *) array
              forObject:(id) object
               forIndex:(int) index;

+ (void) removeImageViewFromCell:(UITableViewCell *) cell;

+ (BOOL) checkGraphHostinView:(CPTPlot *) plot
                  hostingView:(CPTGraphHostingView *) hostingView;

+ (NSArray *) loadData:(ClinicalTrialGov *) clinicalTrialGov
             groupType:(NSString *) type
          measureTitle:mTitle
           measureUnit:(NSString *) unit
         categoryTitle:(NSString *) categoryTitle
      categorySubtitle:(NSString *) categorySubTitle;

+ (NSArray *) getCategorySubtitle:(ClinicalTrialGov *) clinicalTrialGov
                        groupType:(NSString *) type
                     measureTitle:(NSString *) measureTitle;

+ (NSNumber *) getValue:(int) index
         graphDataArray:(NSArray *) array;


+ (NSString *) getGroup:(int) index
         graphDataArray:(NSArray *) array;

+ (NSAttributedString *) getNameValueAttributedString:(NSArray *) array
                                            title:(NSString *) title;
+( NSMutableArray *) addkey:(NSString *)  key
                  keyValue:(id) keyValue
   toDictionaryObjectArray:(NSArray *) dictArray;

+ (BOOL) searchTextInString:(NSString *) string
                searchText:(NSString *) searchText;

+ (NSDictionary *) searchData:(Search *) search
                   searchText:(NSString *) searchText;

+ (void) clearKeyboardAndSearchText:(id) viewController;

+ (NSSet *) getRecents;

+ (void) addRecents:(NSString *) nctId
             search:(NSString *) searchString;

+ (void) setupNotification:(NSString *) notificationName
                       for:(id) identifer
                  selector:(SEL) selector;
+ (void) sendNotification:(NSString *) notificationName
              usingObject:(id) object;
+ (void) removeNotification:(NSString *) notificationName
                        for:(id) identifer;

+ (void) removeRecentsSearchString:(NSString *) searchString;

+ (void) removeRecentsNCTID:(NSString *) nctID;

+ (NSArray *) getOutcomes:(ClinicalTrialGov *) clinicalTrialGov;

@end